package com.ruoyi.business.controller;

import com.ruoyi.business.domain.NoticeInfo;
import com.ruoyi.business.service.INoticeInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/business/noticeInfo")
public class NoticeInfoController extends BaseController {

    @Autowired
    private INoticeInfoService noticeInfoService;

    @GetMapping("/xx")
    public AjaxResult xx(){
        return AjaxResult.success("xx");
    }
    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NoticeInfo noticeInfo)
    {
        startPage();
        List<NoticeInfo> list = noticeInfoService.selectNoticeInfoList(noticeInfo);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NoticeInfo noticeInfo)
    {
        List<NoticeInfo> list = noticeInfoService.selectNoticeInfoList(noticeInfo);
        ExcelUtil<NoticeInfo> util = new ExcelUtil<NoticeInfo>(NoticeInfo.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId)
    {
        return success(noticeInfoService.selectNoticeInfoByNoticeId(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NoticeInfo noticeInfo)
    {
        return toAjax(noticeInfoService.insertNoticeInfo(noticeInfo));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NoticeInfo noticeInfo)
    {
        return toAjax(noticeInfoService.updateNoticeInfo(noticeInfo));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Integer[] noticeIds)
    {
        return toAjax(noticeInfoService.deleteNoticeInfoByNoticeIds(noticeIds));
    }

    //定时推送消息到主页
    @PreAuthorize("@ss.hasPermi('business:noticeInfo:query')")
    @GetMapping("/XX")
    public AjaxResult sendSystemData()
    {
        return success(noticeInfoService.sendSystemData());
    }
}
